import request from "@/utils/request";

// 查询所有可用角色
export function selectAllRole() {
    return request({
        url: '/systemManager/role/selectAllRole',
        method: 'get'
    })
}

// 根据用户ID查询用户拥有的角色IDS
export function getRoleIdsByUserId(userId) {
    return request({
        url: `/systemManager/role/findRolesByUserId/${userId}`,
        method: 'get'
    })
}


//条件查询加分页
export const listRoleForPage = (data) => {
    return request({
        url: "/systemManager/role/findRoleByCond",
        method: "POST",
        data
    })
}

// 添加
export const addRole = ( data) => {
    return request({
        url: '/systemManager/role/addRole',
        method: 'post',
        data
    })
}

// 修改
export function updateRole(data) {
    return request({
        url: '/systemManager/role/updateRole',
        method: 'post',
        data
    })
}

// 查询一个
export function getRoleById(id) {
    return request({
            url: `/systemManager/role/getRoleByRoleId/${id}`,
        method: 'post'
    })
}

// 删除
export function deleteRoleByIds(ids) {
    return request({
        url: `/systemManager/role/deleteRoleByRoleIds/${ids}`,
        method: 'delete'
    })
}

// 保存角色和用户之间的关系
export function saveRoleUser(userId, data) {
    // 处理如果没有选择角色数据。无法匹配后台数据的问题
    return request({
        url: `/systemManager/role/saveRoleUser/${userId}`,
        method: 'post',
        data
    })
}
